#include <stdio.h>
#include <math.h>

//resolution in bits (12 bits or 8 bits)
double calcUmiditate(unsigned char resolution,const unsigned short rawHumidity,short roomTemperature) 
{
double c1 = -4.0, c2, c3, t1 = 0.01, t2;
double RHlinear, RHtrue;

if (resolution == 12)
{
	c2 = 0.0405;
	c3 = -0.0000028;
	t2 = 0.0008;
}
else
{
	c2 = 0.648;
	c3 = -0.00072;
	t2 = 0.00128;
}

RHlinear = c1 + c2 * rawHumidity + c3 * rawHumidity * rawHumidity;
RHtrue = (roomTemperature - 25) * (t1 + t2 * rawHumidity) + RHlinear;
return RHtrue;
}

void main(void)
{
unsigned int rawHumidity;
printf("rawHumidity (8b - max. 255) = ");
scanf("%d",&rawHumidity);

printf("RLtrue = %2.f",calcUmiditate(8,rawHumidity,25));

}

